package com.zpyr.mvc.controller;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import org.mybatis.spring.SqlSessionTemplate;

import com.zpyr.mvc.vo.Carc_evaluation;
import com.zpyr.mvc.vo.Carc_info;
import com.zpyr.mvc.vo.Carc_user_info;

import com.zpyr.mvc.interfaces.CarcMapper;

@Controller
public class CarcWebCont {
	
	@Autowired
	private SqlSessionTemplate sqlSession;
	
	@RequestMapping(value="/carcenter_web.gcm" , params={"!nouse"})
	public ModelAndView index(/*@RequestParam("info_seq")*/ String info_seq) {// RequestParam <- 파라미터가 없으면 400에러를 발생함. 지나친 400에러 발생은 문제의 소지가 있기에 지켜보기로 함.
		
		ModelAndView mav = new ModelAndView("carc/index");
		return mav;
	}

	@RequestMapping(value="/carcenter/web/manageCarcUserInfo.gcm" , params={"!nouse"})
	public ModelAndView manageCarcUserInfo(/*@RequestParam("info_seq")*/ String info_seq) {// RequestParam <- 파라미터가 없으면 400에러를 발생함. 지나친 400에러 발생은 문제의 소지가 있기에 지켜보기로 함.
		
		ModelAndView mav = new ModelAndView("carc/manageCarcUserInfo");
		return mav;
	}

	@Transactional
	@RequestMapping(value="/carcenter/mov/userInfo.gcm" , params={"!nouse"})
	public ModelAndView moveUserInfo(/*@RequestParam("info_seq")*/ String user_info_seq) {// RequestParam <- 파라미터가 없으면 400에러를 발생함. 지나친 400에러 발생은 문제의 소지가 있기에 지켜보기로 함.
		CarcMapper mapper = sqlSession.getMapper(CarcMapper.class);
		
		// carc_user_info 에서 select 하여 carc_info 에 인서트
		mapper.copyUserToInfo( user_info_seq );
		// carc_user_info 에서 삭제
		mapper.deleteCarcUserInfo(user_info_seq);
		
		ModelAndView mav = new ModelAndView("carc/common/isSucYN");
		mav.addObject("isSuccess", "Y");
		return mav;
	}
	
	
		
}